SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





alter    VIEW  v_tb_comexpenditure  
as  
select cast(0 as bit) choice,m.bcode m_bcode,m.bdate m_bdate,m.remark m_remark,m.bkind m_bkind,m.bstate m_bstate,m.bid m_bid,  
    m.dcappamt m_dcappamt,m.create_by m_create_by,m.check_by m_check_by,m.empid m_empid,m.traderid m_traderid,  
    m.balanceid m_balanceid,m.deptid m_deptid,m.voucherid m_voucherid,m.filid m_filid,  
    m.moneyid m_moneyid,mn.code moneycode,mn.name moneyname,m.exchrate m_exchrate,
    m.balanceamt m_balanceamt,m.dcbalanceamt m_dcbalanceamt,
    m.custom1 m_custom1,m.custom2 m_custom2,m.custom3 m_custom3,m.custom4 m_custom4,m.custom5 m_custom5,
    m.custom6 m_custom6,m.custom7 m_custom7,m.custom8 m_custom8,m.custom9 m_custom9,m.custom10 m_custom10,
    m.custom11 m_custom11,m.custom12 m_custom12,m.custom13 m_custom13,m.custom14 m_custom14,m.custom15 m_custom15,
    m.workshopid m_workshopid,w.name m_workshopname,
    m.amount as m_amount,m.dcamount m_dcamount,m.invamt m_invamt,m.invtype m_invtype, m.closeinvoice m_invclose,
    t.Name m_t_name,
    m.projectid m_projectid,pj.code m_pjcode,pj.name m_pjname,    
       d.*,  
       e.id id,e.name as iename
from      tb_comexpenditure m  
left join (select ROW_NUMBER() over (partition by bid order by bno) as bdtlno,* from tb_comexpendituredtl) d on m.bid=d.bid  
left join td_comexpenditure e on d.commexpid=e.id  
left join tfb_voucher vou on (vou.voucherid=m.voucherid)  
left join tfd_vouword ct on (ct.id=vou.vouwordid)  
left join td_balance   b on b.balanceid=m.balanceid  
left join td_account   c on c.accid=m.accountid  
left join v_Td_Account v on v.bankid=c.bankid  
left join td_dept      q on q.ED_DeptID=m.deptid  
left join ts_usersinfo cr on m.create_by=cr.ui_userid  
left join ts_usersinfo ck on m.check_by=ck.ui_userid  
left join td_empmaster em on m.empid = em.em_employeeid   
left join td_trader  t on t.TraderId=m.traderid  
left join td_money mn on m.moneyid=mn.moneyid
left join td_workshop w on m.workshopid=w.workshopid
  left join tfd_project pj on m.projectid=pj.id


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

